-
Notifications
You must be signed in to change notification settings - Fork 6k
Auto detect mode to determine which rendering backend to use. #21852
Conversation
| /// EXPERIMENTAL: Enable the Skia-based rendering backend. | ||
| const bool experimentalUseSkia = | ||
| @JS('window.flutterWebRenderer') | ||
| external String? get customRenderer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "custom renderer" sounds like this is the renderer itself. I'd call this requestedRendererType.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, let's leave dartdocs explaining what it's for.
|
Added @jonahwilliams to reviewer list to have a look at the gn changes. |
jonahwilliams
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gn changes LGTM
nturgut
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The failing test on Cirrus is fixed yesterday, we should sync to head though.
| _autoDetect ? _detectRenderer() : _useSkia; | ||
|
|
||
| /// Returns true if CanvasKit is used. | ||
| /// Otherwise, returns false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nit: I believe there is one empty line between two sentences in doc comments. https://dart.dev/guides/language/effective-dart/documentation#do-separate-the-first-sentence-of-a-doc-comment-into-its-own-paragraph
| if (requestedRendererType != null) { | ||
| return requestedRendererType! == 'canvaskit'; | ||
| } | ||
| // If requestedRendererType is not specified, use CanvasKit for desktop and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yjbanov @ferhatb if I'm not mistaken we are setting Canvaskit as default for desktop. I am personally not sure if we are ready for this step as testing goes:
- Majority of our unit tests are build with canvaskit.
- We have coverage in many critical areas with integration tests on Desktop browsers (text editing, font loading, keyboard, platform selection, image loading, semantics (in draft), scroll (in pr), pointer events (in pr), tree shaking, platform messages). None of them runs with Canvaskit though.
Shall we prioritize running them with Canvaskit then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. We should definitely ramp up testing in CanvasKit mode. This PR is not changing the default yet (--web-renderer=auto will default to CanvasKit on desktop, but --web-renderer itself defaults to html so overall the defaults are not changing), so tests can proceed on their own schedule.
In terms of test prioritization, testing things in CanvasKit mode where the choice of renderer has known effects is a good place to start from. From your list the affected areas are: font loading, image loading. Text editing is also affected but I'm not sure our existing tests will catch the distinction, so we may need new tests. Tree shaking is affected; we use devicelab for that, so it would be best to reuse the existing tests. Other things affected by renderer choice: rendering quality, platform views. There's also performance, but our benchmarks already cover both HTML and CanvasKit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@angjieli tl;dr there's no action items for this PR w.r.t. running existing tests in CanvasKit mode
| /// | ||
| /// Using flutter tools option "--web-render=cavanskit" would set the value to | ||
| /// true. | ||
| /// Using flutter tools option "--web-render=html" would set the value to false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very nit: typo for canvaskit
|
@ferhatb @yjbanov I have an idea for increasing test coverage. When we are running framework tests with local engine, we can run them both with canvaskit and html backend. I'll do that by setting |
yjbanov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (requestedRendererType != null) { | ||
| return requestedRendererType! == 'canvaskit'; | ||
| } | ||
| // If requestedRendererType is not specified, use CanvasKit for desktop and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@angjieli tl;dr there's no action items for this PR w.r.t. running existing tests in CanvasKit mode
|
Is there a way to check whether the HTML is being rendered only, or canvas kit is being rendered only? |
IIRC, you should be able to tell the difference by examining the compiled javascript code. @yjbanov feel free to correct me if I am wrong |
Once you have launched the application in auto mode, you can enter |
|
@angjieli No, my question was - how to detect which mode was set by auto setting, I don't want to explicitly force anything. |
Oh, misread the question. There is no good way to check the rendering backend at this point. IIRC, the info is not exposed to flutter application. |
|
@angjieli |
Yeah. Feel free to file an issue and we can fix it. |

Description
Support auto detect mode to determine which rendering backend to use.
If auto detect is enabled (set by environment variable
FLUTTER_WEB_AUTO_DETECT), developers will be allowed to setwindow.flutterWebRendererto eithercanvaskitorhtmlto select the rendering backend.If
window.flutterWebRendereris not set, flutter engine will usecanvaskitfor desktop device while usinghtmlfor mobile device.If
window.flutterWebRendereris set to an invalid value (notcanvaskitnorhtml), it will default tohtml.If auto detect is disabled, it will check the value of environment variable
FLUTTER_WEB_USE_SKIA. If true, usecanvaksit. Otherwise, usehtml.Tests
Updated some test to reflect this change.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.Reviewer Checklist
Breaking Change
Did any tests fail when you ran them? Please read handling breaking changes.